<html>
<head>
</head>
<body>
<script>
  var gui = require('nw.gui');
  gui.Window.get().showDevTools();
   
  var times = 0;
 
  function open_window(func) {
    var wnd = gui.Window.open("popup.html", {show: false})

    wnd.on("loaded",function(){
      if (times < 8) {
        times += 1;
        func(func);
        console.log(times + 'wait for next.');
      } else {
        console.log(times + 'all done!');
        
        var client = require('../../nw_test_app').createClient({
          argv: gui.App.argv,
          data: "ok"
        });       
      }
      
    });
  }
  
  gui.Window.get().on('close', function() {
    gui.App.quit();
  })
  
  
  open_window(open_window);
  
   
</script>

<button onclick="open_window(open_window)">click</button>

</body>
</html>
